<?php
/**
 * Test.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2018/12/10
 * Time: 15:45
 */
namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Test extends Command {
    protected function configure(){
        // php think test jiangxiaobo          41 --options1 abc --options2 111
        $this->setName('test')->setDescription('Here is the remark')
            ->addArgument('argv',Argument::IS_ARRAY,'argv')
            // VALUE_REQUIRED 是必填的选项,VALUE_OPTIONAL 是可选
            ->addOption('options1',null,Option::VALUE_REQUIRED,'options1')
            ->addOption('options2',null,Option::VALUE_REQUIRED,'options2');
    }
    protected function execute(Input $input, Output $output){
        /**
         * $input->getOptions()
         * array(9) {
        'options1' =>
        string(3) "abc"
        'options2' =>
        string(3) "111"
        'help' =>
        bool(false)
        'version' =>
        bool(false)
        'quiet' =>
        bool(false)
        'verbose' =>
        bool(false)
        'ansi' =>
        bool(false)
        'no-ansi' =>
        bool(false)
        'no-interaction' =>
        bool(false)
        }
         *
         * $input->getArguments()
         * array(2) {
        'command' =>
        string(4) "test"
        'argv' =>
        array(2) {
        [0] =>
        string(11) "jiangxiaobo"
        [1] =>
        string(2) "41"
        }
        }
         */
        var_dump($input->getOptions());
        var_dump($input->getArguments());
        $output->writeln("TestCommand:");
        var_dump(APP_PATH);
    }
}